package com.github.gdxmap;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidFragmentApplication;
import com.github.gdxmap.core.GdxMapListener;
import com.github.gdxmap.core.MapFragment;
import com.github.gdxmap.core.MapOptions;
import com.github.gdxmap.layer.Layer;
import com.github.gdxmap.layer.format.GeoJsonLayer;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements AndroidFragmentApplication.Callbacks,GdxMapListener {
    MapFragment mapFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mapFragment=new MapFragment();
        mapFragment.setGdxMapListener(this);

        getSupportFragmentManager().beginTransaction()
                .add(R.id.activity_main,mapFragment)
                .commit();
    }

    @Override
    public void exit() {

    }

    @Override
    public void loadFinish() {
        List<Layer> layerList=new ArrayList<>();

        GeoJsonLayer geoJsonLayer=new GeoJsonLayer(getApplicationContext(), URI.create("file:///android_asset/map_line.geojson"));
        GeoJsonLayer geoJsonLayer2=new GeoJsonLayer(getApplicationContext(), URI.create("file:///android_asset/map_point.geojson"));
        GeoJsonLayer geoJsonLayer3=new GeoJsonLayer(getApplicationContext(), URI.create("file:///android_asset/map_polygon.geojson"));

        layerList.add(geoJsonLayer);
//        layerList.add(geoJsonLayer2);
        layerList.add(geoJsonLayer3);

        MapOptions mapOptions=new MapOptions();

        mapOptions.setMinZoom(0);
        mapOptions.setMaxZoom(6);
        mapOptions.setZoomAnimation(true);
        mapOptions.setLayers(layerList);

        mapFragment.initialize(mapOptions);
    }
}
